
/*

Design Pattern Automation Toolkit.
Application to create applications with emphasis on Design patterns.
And support for round trip engineering.
Copyright (C) 2004 Vineeth Neelakant. nvineeth@gmail.com

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

*/
using System;
using BusinessLayer;
using InfoClasses;
using dpatoolkit.UILayer;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;

namespace dpatoolkit.UILayer
{
    /// <summary>
    /// Summary description for AddFieldForm..
    /// </summary>
    public class AddFieldForm : System.Windows.Forms.Form
    {
        private System.Windows.Forms.TextBox summaryTextBox;
        private System.Windows.Forms.TextBox fieldNameTextBox;
        private System.Windows.Forms.ComboBox visibilityComboBox;
        private System.Windows.Forms.Button cancelButton;
        private System.Windows.Forms.Button okButton;
        private System.Windows.Forms.TextBox fieldTypeTextBox;
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.Container components = null;
        private string fldType, fldName, visibility, summary;
        private GroupBox groupBox1;
        private GroupBox groupBox2;
        private GroupBox groupBox3;
        private GroupBox groupBox4;
        private System.Windows.Forms.Button metaInfoButton;


        public AddFieldForm()
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

            this.visibilityComboBox.SelectedIndex = 0;
        }

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (components != null)
                {
                    components.Dispose();
                }
            }
            base.Dispose(disposing);
        }

        #region Windows Form Designer generated code
        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.summaryTextBox = new System.Windows.Forms.TextBox();
            this.fieldNameTextBox = new System.Windows.Forms.TextBox();
            this.visibilityComboBox = new System.Windows.Forms.ComboBox();
            this.cancelButton = new System.Windows.Forms.Button();
            this.okButton = new System.Windows.Forms.Button();
            this.fieldTypeTextBox = new System.Windows.Forms.TextBox();
            this.metaInfoButton = new System.Windows.Forms.Button();
            this.groupBox1 = new System.Windows.Forms.GroupBox();
            this.groupBox2 = new System.Windows.Forms.GroupBox();
            this.groupBox3 = new System.Windows.Forms.GroupBox();
            this.groupBox4 = new System.Windows.Forms.GroupBox();
            this.groupBox1.SuspendLayout();
            this.groupBox2.SuspendLayout();
            this.groupBox3.SuspendLayout();
            this.groupBox4.SuspendLayout();
            this.SuspendLayout();
            // 
            // summaryTextBox
            // 
            this.summaryTextBox.AcceptsReturn = true;
            this.summaryTextBox.Location = new System.Drawing.Point(6, 19);
            this.summaryTextBox.Multiline = true;
            this.summaryTextBox.Name = "summaryTextBox";
            this.summaryTextBox.ScrollBars = System.Windows.Forms.ScrollBars.Both;
            this.summaryTextBox.Size = new System.Drawing.Size(471, 75);
            this.summaryTextBox.TabIndex = 3;
            // 
            // fieldNameTextBox
            // 
            this.fieldNameTextBox.Location = new System.Drawing.Point(6, 28);
            this.fieldNameTextBox.Name = "fieldNameTextBox";
            this.fieldNameTextBox.Size = new System.Drawing.Size(272, 20);
            this.fieldNameTextBox.TabIndex = 1;
            this.fieldNameTextBox.Text = "fieldName";
            // 
            // visibilityComboBox
            // 
            this.visibilityComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
            this.visibilityComboBox.Items.AddRange(new object[] {
            "public",
            "protected",
            "private"});
            this.visibilityComboBox.Location = new System.Drawing.Point(6, 19);
            this.visibilityComboBox.Name = "visibilityComboBox";
            this.visibilityComboBox.Size = new System.Drawing.Size(152, 21);
            this.visibilityComboBox.TabIndex = 2;
            // 
            // cancelButton
            // 
            this.cancelButton.DialogResult = System.Windows.Forms.DialogResult.Cancel;
            this.cancelButton.Location = new System.Drawing.Point(456, 320);
            this.cancelButton.Name = "cancelButton";
            this.cancelButton.Size = new System.Drawing.Size(80, 24);
            this.cancelButton.TabIndex = 6;
            this.cancelButton.Text = "&CANCEL";
            // 
            // okButton
            // 
            this.okButton.DialogResult = System.Windows.Forms.DialogResult.OK;
            this.okButton.Location = new System.Drawing.Point(360, 320);
            this.okButton.Name = "okButton";
            this.okButton.Size = new System.Drawing.Size(75, 23);
            this.okButton.TabIndex = 5;
            this.okButton.Text = "&OK";
            this.okButton.Click += new System.EventHandler(this.okButton_Click);
            // 
            // fieldTypeTextBox
            // 
            this.fieldTypeTextBox.Location = new System.Drawing.Point(0, 19);
            this.fieldTypeTextBox.Name = "fieldTypeTextBox";
            this.fieldTypeTextBox.Size = new System.Drawing.Size(264, 20);
            this.fieldTypeTextBox.TabIndex = 0;
            this.fieldTypeTextBox.Text = "FieldType";
            // 
            // metaInfoButton
            // 
            this.metaInfoButton.FlatStyle = System.Windows.Forms.FlatStyle.System;
            this.metaInfoButton.Location = new System.Drawing.Point(24, 320);
            this.metaInfoButton.Name = "metaInfoButton";
            this.metaInfoButton.Size = new System.Drawing.Size(75, 23);
            this.metaInfoButton.TabIndex = 4;
            this.metaInfoButton.Text = "&MetaInfo >>";
            this.metaInfoButton.Click += new System.EventHandler(this.metaInfoButton_Click);
            // 
            // groupBox1
            // 
            this.groupBox1.Controls.Add(this.fieldNameTextBox);
            this.groupBox1.Location = new System.Drawing.Point(24, 12);
            this.groupBox1.Name = "groupBox1";
            this.groupBox1.Size = new System.Drawing.Size(512, 67);
            this.groupBox1.TabIndex = 18;
            this.groupBox1.TabStop = false;
            this.groupBox1.Text = "Field Name";
            // 
            // groupBox2
            // 
            this.groupBox2.Controls.Add(this.fieldTypeTextBox);
            this.groupBox2.Location = new System.Drawing.Point(30, 85);
            this.groupBox2.Name = "groupBox2";
            this.groupBox2.Size = new System.Drawing.Size(506, 55);
            this.groupBox2.TabIndex = 19;
            this.groupBox2.TabStop = false;
            this.groupBox2.Text = "Field Type";
            // 
            // groupBox3
            // 
            this.groupBox3.Controls.Add(this.visibilityComboBox);
            this.groupBox3.Location = new System.Drawing.Point(24, 146);
            this.groupBox3.Name = "groupBox3";
            this.groupBox3.Size = new System.Drawing.Size(512, 51);
            this.groupBox3.TabIndex = 20;
            this.groupBox3.TabStop = false;
            this.groupBox3.Text = "Visibility";
            // 
            // groupBox4
            // 
            this.groupBox4.Controls.Add(this.summaryTextBox);
            this.groupBox4.Location = new System.Drawing.Point(24, 203);
            this.groupBox4.Name = "groupBox4";
            this.groupBox4.Size = new System.Drawing.Size(512, 100);
            this.groupBox4.TabIndex = 21;
            this.groupBox4.TabStop = false;
            this.groupBox4.Text = "Summary";
            // 
            // AddFieldForm
            // 
            this.AcceptButton = this.okButton;
            this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
            this.CancelButton = this.cancelButton;
            this.ClientSize = new System.Drawing.Size(562, 352);
            this.Controls.Add(this.groupBox4);
            this.Controls.Add(this.groupBox3);
            this.Controls.Add(this.groupBox2);
            this.Controls.Add(this.groupBox1);
            this.Controls.Add(this.metaInfoButton);
            this.Controls.Add(this.cancelButton);
            this.Controls.Add(this.okButton);
            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
            this.Name = "AddFieldForm";
            this.Text = "Add Field";
            this.groupBox1.ResumeLayout(false);
            this.groupBox1.PerformLayout();
            this.groupBox2.ResumeLayout(false);
            this.groupBox2.PerformLayout();
            this.groupBox3.ResumeLayout(false);
            this.groupBox4.ResumeLayout(false);
            this.groupBox4.PerformLayout();
            this.ResumeLayout(false);

        }
        #endregion



        private void okButton_Click(object sender, System.EventArgs e)
        {

            this.fldName = this.fieldNameTextBox.Text;
            this.fldType = this.fieldTypeTextBox.Text;
            this.visibility = this.visibilityComboBox.SelectedItem as string;
            this.summary = this.summaryTextBox.Text;
            if (this.fldName.Length == 0 || this.fldType.Length == 0)
            {
                ErrorMessage.Show("Field Name or Field Type cannot be null,\n these modifications will not be added", "Value required");
                this.error = true;
                return;
            }


        }

        public string FieldType
        {
            set { this.fieldTypeTextBox.Text = value; }
            get { return this.fldType; }
        }
        public string FieldName
        {
            set { this.fieldNameTextBox.Text = value; }
            get { return this.fldName; }
        }
        public string Visibility
        {
            set
            {
                string str = value as string;
                if (str == "private")
                    this.visibilityComboBox.SelectedIndex = 2;
                else if (str == "public")
                    this.visibilityComboBox.SelectedIndex = 0;
                else
                    this.visibilityComboBox.SelectedIndex = 1;

            }
            get { return this.visibility; }

        }

        public string Summary
        {
            set { this.summaryTextBox.Text = value; }
            get { return this.summary; }
        }

        private string metaInfo = "";
        public string MetaInfo
        {
            get
            {
                return this.metaInfo;
            }
            set
            {
                this.metaInfo = value;
            }

        }

        private void metaInfoButton_Click(object sender, System.EventArgs e)
        {
            MetaInfoEditor mie = new MetaInfoEditor(this.metaInfo);
            if (mie.ShowDialog() == DialogResult.Cancel)
                return;
            this.metaInfo = mie.MetaInfo;

        }



        private bool error = false;
        public bool HasErrors()
        {
            return error;
        }



    }
}
